using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;

namespace produccion.clases
{

   public  class CLSDETORDD : ObservableObject
    {

MDOgeneral mod = new MDOgeneral();

#region metodos
        
       public int insertar() {
        try {
            string query = "insert into detordd (NROORD_DOD,CODREF_DOD,CODCOL_DOD,CODTAL_DOD,CANPRO_DOD,PREPRO_DOD) values ('"+NROORD_DOD+"','"+CODREF_DOD+"','"+CODCOL_DOD+"','"+CODTAL_DOR+"',"+CANPRO_DOD+","+PREPRO_DOD+")";
            return mod.comando(query);
        }
        catch (Exception ex) { throw ex; }
        }

       public int actualizar() {
        try {
            string query = "update detordd set CANPRO_DOD=" + CANPRO_DOD + ",PREPRO_DOD=" + PREPRO_DOD + " where NROORD_DOD='" + NROORD_DOD + "' and CODREF_DOD='"+CODREF_DOD+"' and CODCOL_DOD='"+CODCOL_DOD+"' and CODTAL_DOR='"+CODTAL_DOR+"'";
            return mod.comando(query);
        }
        catch (Exception ex) { throw ex; }
        }

       public Boolean existe() {
        try {
            string query = "select count(*) from detordd where NROORD_DOD='" + NROORD_DOD + "' and CODREF_DOD='"+CODREF_DOD+"' and CODCOL_DOD='"+CODCOL_DOD+"' and CODTAL_DOR='"+CODTAL_DOR+"'";
            DataTable val = mod.consulta(query);
            if (val.Rows.Count > 0) {
                if (Convert.ToUInt32(val.Rows[0][0])>0) {
                    return true;
                }
            }
            return false;
        }
        catch (Exception ex) { throw ex; }
        }

       public List<CLSDETORDD> consultar() {
           try {
               string query = "select nroord_dod,codref_dod,codcol_dod,codtal_dor, canpro_dod,prepro_dod from detordd where nroord_dod='"+NROORD_DOD+"'";
               DataTable val=mod.consulta(query);
               List<CLSDETORDD> lista = new List<CLSDETORDD>();
               foreach (DataRow dr in val.Rows) {
                   lista.Add(new CLSDETORDD {
                       NROORD_DOD = dr["NROORD_DOD"].ToString(),
                       CODREF_DOD=dr["CODREF_DOD"].ToString(),
                       CODCOL_DOD=dr["CODCOL_DOD"].ToString(),
                       CODTAL_DOR = dr["CODTAL_DOR"].ToString(),
                       CANPRO_DOD = Convert.ToInt32(dr["CANPRO_DOD"]),
                       PREPRO_DOD = Convert.ToInt32(dr["PREPRO_DOD"])
                   });
               }
               return lista;
           }
           catch (Exception ex) { throw ex; }
       }
        
#endregion

#region propiedades
        
        string _NROORD_DOD;
        public string NROORD_DOD{
        get{return _NROORD_DOD;}
            set{
                _NROORD_DOD=value;
                RaisePropertyChangedEvent("NROORD_DOD");
            }
        }

        string _CODREF_DOD;
        public string CODREF_DOD{
        get{return _CODREF_DOD;}
            set{
                _CODREF_DOD=value;
                RaisePropertyChangedEvent("CODREF_DOD");
            }
        }

        string _CODCOL_DOD;
        public string CODCOL_DOD{
        get{return _CODCOL_DOD;}
            set{
                _CODCOL_DOD=value;
                RaisePropertyChangedEvent("CODCOL_DOD");
            }
        }

        string _CODTAL_DOR;
        public string CODTAL_DOR{
        get{return _CODTAL_DOR;}
            set{
                _CODTAL_DOR=value;
                RaisePropertyChangedEvent("CODTAL_DOR");
            }
        }

        int _CANPRO_DOD;
        public int CANPRO_DOD{
        get{return _CANPRO_DOD;}
            set{
                _CANPRO_DOD=value;
                RaisePropertyChangedEvent("CANPRO_DOD");
            }
        }

        int _PREPRO_DOD;
        public int PREPRO_DOD
        {
            get { return _PREPRO_DOD; }
            set{
                _PREPRO_DOD = value;
                RaisePropertyChangedEvent("PREPRO_DOD");
            }
        }

#endregion

    }
}
